package org.lock4j.service;

import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.lock.executor.RedissonLockExecutor;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author yexi
 */
@Service
public class CustomService {

    /**
     * 此 @Lock4j 注解基于 Spring AOP 实现。
     */
    @Lock4j(keys = {"#key"}, acquireTimeout = 5 * 1000, expire = 10 * 1000
            , executor = RedissonLockExecutor.class
    )
    public String lockMethod(String key) throws InterruptedException {
        // 模拟业务处理
        TimeUnit.SECONDS.sleep(3);
        return "业务要返回的数据";
    }


}
